// test mylua lib
#include <lua.h>
#include <lauxlib.h>
#include <stdio.h>
#include <uuid/uuid.h>

static int ltest1(lua_State *L) {
    int num = luaL_checkinteger(L, 1);
    printf("--- ltest1, num:%d\n", num);
    return 0;
}

static int lguid(lua_State *L) {
    uuid_t uuid;
    uuid_generate(uuid);
    
    char lstr[37];
    uuid_unparse(uuid, lstr);
    lua_pushlstring(L, (char *)uuid, sizeof(uuid_t));
    printf("--- lguid, guid gen:%s\n", lstr);

    unsigned char *p = uuid;
    int i;
    for (i = 0; i < sizeof(uuid_t); i++, p++)
    {
        printf("%02x", *p);
    }
    printf("\n");

    return 1;
}

int luaopen_mylualib(lua_State *L) {

    luaL_Reg l[] = {
        { "guid", lguid },
        { "test1", ltest1 },
        { NULL, NULL },
    };
    luaL_newlib(L, l);

    return 1;
}  